//
//  ViewController.m
//  02_拉勾的3个界面
//
//  Created by dllo on 16/7/16.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "LoginViewController.h"
#import "AccountView.h"
#import "RegisterViewController.h"
#import "ForgetViewController.h"

@interface LoginViewController ()
@property (nonatomic, strong) AccountView *userNameView;
@property (nonatomic, strong) AccountView *passwordView;
@end

@implementation LoginViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = YES;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
//    UIBlurEffect *blur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
//    UIVisualEffectView *visualView = [[UIVisualEffectView alloc] initWithEffect: blur];
//    visualView.frame = self.view.frame;
//    [self.view addSubview:visualView];
//    visualView.alpha = 0.8;
    
    UIImageView *welcomeImageView = [[UIImageView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    welcomeImageView.image = [UIImage imageNamed:@"welcome_2"];
    [self.view addSubview:welcomeImageView];
    
    UIImageView *lagouImageView = [[UIImageView alloc] initWithFrame:CGRectMake(147, 93, 120, 185)];
    lagouImageView.image = [UIImage imageNamed:@"logo_lagou"];
    [self.view addSubview:lagouImageView];
    
    self.userNameView = [[AccountView alloc] initWithFrame:CGRectMake(20, 331, 374, 55) image:[UIImage imageNamed:@"icon_username"]];
    UIBezierPath *userMaskPath = [UIBezierPath bezierPathWithRoundedRect:self.userNameView.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(5, 5)];
    CAShapeLayer *userMaskLayer = [[CAShapeLayer alloc] init];
    userMaskLayer.frame = self.userNameView.bounds;
    userMaskLayer.path = userMaskPath.CGPath;
    self.userNameView.layer.mask = userMaskLayer;
    self.userNameView.textField.placeholder = @"请输入已验证手机号或邮箱";
    [self.userNameView.textField setValue:[UIColor grayColor] forKeyPath:@"_placeholderLabel.textColor"];
    [self.view addSubview:self.userNameView];
    
    self.passwordView = [[AccountView alloc] initWithFrame:CGRectMake(20, 388, 374, 55) image:[UIImage imageNamed:@"icon_password"]];
    UIBezierPath *passwordMaskPath = [UIBezierPath bezierPathWithRoundedRect:self.userNameView.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(5, 5)];
    CAShapeLayer *passwordMaskLayer = [[CAShapeLayer alloc] init];
    passwordMaskLayer.frame = self.passwordView.bounds;
    passwordMaskLayer.path = passwordMaskPath.CGPath;
    self.passwordView.layer.mask = passwordMaskLayer;
    self.passwordView.textField.placeholder = @"请输入密码";
    [self.passwordView.textField setValue:[UIColor grayColor] forKeyPath:@"_placeholderLabel.textColor"];
    [self.view addSubview:self.passwordView];
    
    UIButton *forgetButton = [UIButton buttonWithType:UIButtonTypeCustom];
    forgetButton.backgroundColor = [UIColor clearColor];
    [forgetButton setImage:[UIImage imageNamed:@"forget"] forState:UIControlStateNormal];
    [forgetButton setTitle:@" 忘记密码" forState:UIControlStateNormal];
    [forgetButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
    forgetButton.frame = CGRectMake(285, 459, 109, 23);
    [forgetButton addTarget:self action:@selector(forgetAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:forgetButton];
    
    UIButton *loginButton = [UIButton buttonWithType:UIButtonTypeCustom];
    loginButton.backgroundColor = [UIColor colorWithRed:59 / 255.0f green:165 / 255.0f blue:117 / 255.0f alpha:1];
    [loginButton setTitle:@"登录" forState:UIControlStateNormal];
    [loginButton setTitleColor:[UIColor colorWithRed:69 / 255.0f green:188 / 255.0f blue:150 / 255.0f alpha:1] forState:UIControlStateNormal];
    loginButton.frame = CGRectMake(20, 519, 374, 50);
    loginButton.layer.cornerRadius = 5;
    [self.view addSubview:loginButton];
    [loginButton addTarget:self action:@selector(login) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton *registerButton = [UIButton buttonWithType:UIButtonTypeCustom];
    registerButton.backgroundColor = [UIColor clearColor];
    registerButton.layer.cornerRadius = 5;
    registerButton.layer.borderColor = [UIColor colorWithRed:49 / 255.0f green:134 / 255.0f blue:101 / 255.0f alpha:1].CGColor;
    registerButton.layer.borderWidth = 1;
    [registerButton setTitle:@"注册拉勾" forState:UIControlStateNormal];
    [registerButton setTitleColor:[UIColor colorWithRed:0 green:161 / 255.0f blue:123 / 255.0f alpha:1] forState:UIControlStateNormal];
    registerButton.frame = CGRectMake(20, 591, 374, 50);
    [registerButton addTarget:self action:@selector(registerAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:registerButton];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)registerAction {
    RegisterViewController *registerVC = [[RegisterViewController alloc] init];
    [self presentViewController:registerVC animated:YES completion:nil];
}

- (void)login {
    NSLog(@"登陆成功");
}

- (void)forgetAction {
    NSLog(@"dasdasda");
    ForgetViewController *forgetVC = [[ForgetViewController alloc] init];
    // 先设置返回按钮,再push
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] init];
    backItem.title = @"返回";
    [backItem setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor colorWithRed:61 / 255.0f green:170 / 255.0f blue:123 / 255.0f alpha:1]} forState:UIControlStateNormal];
    self.navigationItem.backBarButtonItem = backItem;
    [self.navigationController pushViewController:forgetVC animated:NO];
}

@end
